Trò chơi đua xe động vật trong UNITY Engine
114.960 lượt xem;
- InterpolationBounceOut.cs
- Interpolations /
- Bapk /
- Scripts /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4 public class InterpolationBounceOut : InterpolationProcess {
5
6 protected float[] widths, heights;
7
8 private float width;
9 private float height;
10
11 public InterpolationBounceOut(float[] widths, float[] heights)
12 {
13 this.widths = widths;
14 this.heights = heights;
15 }
16
17 public InterpolationBounceOut(int bounces)
18 {
19 if (bounces < 2 || bounces > 5) return;
20 widths = new float[bounces];
21 heights = new float[bounces];
22 heights[0] = 1;
23 switch (bounces)
24 {
25 case 2:
26 widths[0] = 0.6f;
27 widths[1] = 0.4f;
28 heights[1] = 0.33f;
29 break;
30 case 3:
31 widths[0] = 0.4f;
32 widths[1] = 0.4f;
33 widths[2] = 0.2f;
34 heights[1] = 0.33f;
35 heights[2] = 0.1f;
36 break;
37 case 4:
38 widths[0] = 0.34f;
39 widths[1] = 0.34f;
40 widths[2] = 0.2f;
41 widths[3] = 0.15f;
42 heights[1] = 0.26f;
43 heights[2] = 0.11f;
44 heights[3] = 0.03f;
45 break;
46 case 5:
47 widths[0] = 0.3f;
48 widths[1] = 0.3f;
49 widths[2] = 0.2f;
50 widths[3] = 0.1f;
51 widths[4] = 0.1f;
52 heights[1] = 0.45f;
53 heights[2] = 0.3f;
54 heights[3] = 0.15f;
55 heights[4] = 0.06f;
56 break;
57 }
58 widths[0] *= 2;
59 }
60
61 public override float apply(float a)
62 {
63 a += widths[0] / 2;
64 width = 0;
65 height = 0;
66 for (int i = 0, n = widths.Length; i < n; i++)
67 {
68 width = widths[i];
69 if (a <= width)
70 {
71 height = heights[i];
72 break;
73 }
74 a -= width;
75 }
76 a /= width;
77 float z = 4 / width * height * a;
78 return 1 - (z - z * a) * width;
79 }
80 }
2 using System.Collections;
3
4 public class InterpolationBounceOut : InterpolationProcess {
5
6 protected float[] widths, heights;
7
8 private float width;
9 private float height;
10
11 public InterpolationBounceOut(float[] widths, float[] heights)
12 {
13 this.widths = widths;
14 this.heights = heights;
15 }
16
17 public InterpolationBounceOut(int bounces)
18 {
19 if (bounces < 2 || bounces > 5) return;
20 widths = new float[bounces];
21 heights = new float[bounces];
22 heights[0] = 1;
23 switch (bounces)
24 {
25 case 2:
26 widths[0] = 0.6f;
27 widths[1] = 0.4f;
28 heights[1] = 0.33f;
29 break;
30 case 3:
31 widths[0] = 0.4f;
32 widths[1] = 0.4f;
33 widths[2] = 0.2f;
34 heights[1] = 0.33f;
35 heights[2] = 0.1f;
36 break;
37 case 4:
38 widths[0] = 0.34f;
39 widths[1] = 0.34f;
40 widths[2] = 0.2f;
41 widths[3] = 0.15f;
42 heights[1] = 0.26f;
43 heights[2] = 0.11f;
44 heights[3] = 0.03f;
45 break;
46 case 5:
47 widths[0] = 0.3f;
48 widths[1] = 0.3f;
49 widths[2] = 0.2f;
50 widths[3] = 0.1f;
51 widths[4] = 0.1f;
52 heights[1] = 0.45f;
53 heights[2] = 0.3f;
54 heights[3] = 0.15f;
55 heights[4] = 0.06f;
56 break;
57 }
58 widths[0] *= 2;
59 }
60
61 public override float apply(float a)
62 {
63 a += widths[0] / 2;
64 width = 0;
65 height = 0;
66 for (int i = 0, n = widths.Length; i < n; i++)
67 {
68 width = widths[i];
69 if (a <= width)
70 {
71 height = heights[i];
72 break;
73 }
74 a -= width;
75 }
76 a /= width;
77 float z = 4 / width * height * a;
78 return 1 - (z - z * a) * width;
79 }
80 }